package com.example.Lezedata.ui.mePage;

import androidx.lifecycle.ViewModelProvider;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.Lezedata.R;
import com.example.Lezedata.dataManager.LoginManager;
import com.example.Lezedata.ui.activity.login.LoginVc;
import com.example.Lezedata.ui.fragment.BaseFragment;
import com.example.Lezedata.ui.fragment.commonfragment.AlertFragment;
import com.example.Lezedata.util.GBActivityManager;

public class MePageFragment extends BaseFragment {

    private MePageViewModel mViewModel;

    public static MePageFragment newInstance() {
        return new MePageFragment();
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.tab_me_page_fragment, container, false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mViewModel = new ViewModelProvider(this).get(MePageViewModel.class);
        // TODO: Use the ViewModel
    }

    private TextView InvCode;
    private TextView LoginOut;

    @Override
    public void initView() {
        super.initView();
//        InvCode = findViewById(R.id.InvCode);
        LoginOut = findViewById(R.id.loginOut);

//        InvCode.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                gotoInvCoe();
//            }
//        });

        LoginOut.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                loginOut();
            }
        });
    }

//    void gotoInvCoe(){
//        baseVc().jumpActivity(MeInvCodeVc.class);
//    }

    void loginOut(){
        AlertFragment fragment = new AlertFragment();
        fragment.text = "退出登录？";
        fragment.okListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                GBActivityManager.sharedManager().finishAllActivity();
                baseVc().jumpActivity(LoginVc.class);
                LoginManager.instance().exitLogin();
            }
        };
        fragment.show(getParentFragmentManager(),"alert");
    }
}
